<?xml version="1.0" encoding="utf-8"?>
<xsl:stylesheet version="1.0" xmlns:xsl="http://www.w3.org/1999/XSL/Transform" xmlns:zj="http://www.zju.edu.cn" xmlns:y="http://www.zju.edu.cn/ZJ" exclude-result-prefixes="zj y">
  <xsl:template name="zj:Input">
    <xsl:param name="Field"/>
    <xsl:param name="Value"/>
    <xsl:param name="Pos"/>
    <xsl:param name="HtmlCtrl"/>
    <xsl:variable name="InputType">
      <xsl:choose>
        <xsl:when test="$HtmlCtrl='EasySearch'">Text</xsl:when>
        <xsl:otherwise>
          <xsl:value-of select="$HtmlCtrl"/>
        </xsl:otherwise>
      </xsl:choose>
    </xsl:variable>
    <xsl:call-template name="zj:Caption">
      <xsl:with-param name="IsEmpty" select="$Field/@IsEmpty = 'true'"/>
      <xsl:with-param name="Title" select="$Field/zj:DisplayName"/>
    </xsl:call-template>
    <td class="td-right">
      <xsl:call-template name="zj:IsTwoColumn">
        <xsl:with-param name="IsTwoColumn" select="$Field/zj:Display/@ThreeColumn"/>
      </xsl:call-template>
      <xsl:call-template name="y:ProcessError">
        <xsl:with-param name="FieldName" select="$Field/zj:FieldName"/>
        <xsl:with-param name="Pos" select="$Pos"/>
      </xsl:call-template>
      <xsl:variable name="ReadOnly" select="$Field/zj:Display/@ReadOnly = 'true'"/>
      <input type="{$InputType}" name="{$Field/zj:FieldName}" id="{$Field/zj:FieldName}">
        <xsl:choose>
          <xsl:when test="$Field/@DataType='Date'">
            <xsl:attribute name="class">wid80 easyui-datebox</xsl:attribute>
            <xsl:attribute name="value"><xsl:value-of select="substring($Value, 1, 10)"/></xsl:attribute>
          </xsl:when>
          <xsl:when test="$Field/@DataType='DateTime'">
            <xsl:attribute name="class">wid80 easyui-datetimebox</xsl:attribute>
            <xsl:attribute name="value"><xsl:value-of select="translate(substring($Value, 1, 19), 'T', ' ')"/></xsl:attribute>
          </xsl:when>
          <xsl:when test="$HtmlCtrl='EasySearch'">
            <xsl:attribute name="class">wid80</xsl:attribute>
            <xsl:attribute name="value"><xsl:value-of select="$zj:Toolkit/*[local-name()=$Field/zj:FieldName][CODE_VALUE=$Value]/CODE_NAME"/></xsl:attribute>
          </xsl:when>
          <xsl:when test="$InputType='CheckBox'">
            <xsl:call-template name="y:CheckBox">
              <xsl:with-param name="Field" select="$Field"/>
              <xsl:with-param name="Value" select="$Value"/>
            </xsl:call-template>
          </xsl:when>         
          <xsl:otherwise>
            <xsl:variable name="UIControl" select="$Field/zj:HtmlCtrl/*[1]"></xsl:variable>
            <xsl:choose>
              <xsl:when test="local-name($UIControl) = 'ValidateBox'">
                <xsl:attribute name="class">wid90 easyui-validatebox</xsl:attribute>
                <xsl:call-template name="zj:ValidateBox">
                  <xsl:with-param name="UIControl" select="$UIControl"/>
                </xsl:call-template>   
              </xsl:when>
              <xsl:otherwise>
                <xsl:attribute name="class">wid90</xsl:attribute>              
              </xsl:otherwise>
            </xsl:choose>
            <xsl:attribute name="value">
              <xsl:call-template name="zj:FormatNumber">
                <xsl:with-param name="Field" select="$Field"/>
                <xsl:with-param name="Value" select="$Value"/>
              </xsl:call-template>
            </xsl:attribute>
          </xsl:otherwise>
        </xsl:choose>
        <xsl:if test="$ReadOnly">
          <xsl:attribute name="readonly">readonly</xsl:attribute>
        </xsl:if>
        <xsl:call-template name="y:CopyAttribute">
          <xsl:with-param name="Field" select="$Field"/>
          <xsl:with-param name="Value" select="$Value"/>
          <xsl:with-param name="Pos" select="$Pos"/>
        </xsl:call-template>
      </input>      
      <xsl:if test="$HtmlCtrl='EasySearch' and not($ReadOnly)">
        <img src="../images/lookup.gif" alt="查询" style="WIDTH: 18px;height=17px;border=0;cursor:hand" align="middle" width="18" height="17" name="Img{$Field/zj:FieldName}">
          <xsl:attribute name="onclick">setLastMousePosition(event);<xsl:value-of select="$Field/zj:Extension/@ImgClick"/></xsl:attribute>
        </img>
      </xsl:if>
      <xsl:call-template name="y:ProcessHint">
        <xsl:with-param name="Field" select="$Field"/>
      </xsl:call-template>
    </td>
  </xsl:template>
  <xsl:template name="zj:EasySearch">
    <xsl:param name="Field"/>
    <xsl:param name="Value"/>
    <xsl:param name="Pos"/>
    <xsl:variable name="CodeTable" select="$zj:Toolkit/*[local-name()=$Field/zj:FieldName]"/>
    <xsl:variable name="ErrorField" select="$zj:Toolkit/ERROR[FIELD_NAME=$Field/zj:FieldName][ERROR_POS = $Pos - 1]"/>
    <xsl:choose>
      <xsl:when test="$ErrorField/ERROR_VALUE='数据有二义性'">
        <xsl:call-template name="zj:Combo">
          <xsl:with-param name="Field" select="$Field"/>
          <xsl:with-param name="Value" select="$Value"/>
          <xsl:with-param name="Pos" select="$Pos"/>
        </xsl:call-template>
        <input type="hidden" name="hd{$Field/zj:FieldName}" id="hd{$Field/zj:FieldName}" value="hd~SELECT~"/>
      </xsl:when>
      <xsl:otherwise>
        <xsl:call-template name="zj:Input">
          <xsl:with-param name="Field" select="$Field"/>
          <xsl:with-param name="Value" select="$Value"/>
          <xsl:with-param name="Pos" select="$Pos"/>
          <xsl:with-param name="HtmlCtrl" select="'EasySearch'"/>
        </xsl:call-template>
        <input type="hidden" name="hd{$Field/zj:FieldName}" id="hd{$Field/zj:FieldName}" value="{$Value}"/>
      </xsl:otherwise>
    </xsl:choose>
    <input type="hidden" name="hd{$Field/zj:FieldName}Type" id="hd{$Field/zj:FieldName}Type" value="{$Field/zj:EasySearch/@RegName}"/>
  </xsl:template>
  <xsl:template name="zj:MultiSelect">
    <xsl:param name="Field"/>
    <xsl:param name="Value"/>
    <xsl:call-template name="zj:Caption">
      <xsl:with-param name="IsEmpty" select="$Field/@IsEmpty = 'true'"/>
      <xsl:with-param name="Title" select="$Field/zj:DisplayName"/>
    </xsl:call-template>
    <td class="td-right">
      <xsl:call-template name="zj:IsTwoColumn">
        <xsl:with-param name="IsTwoColumn" select="$Field/zj:Display/@ThreeColumn"/>
      </xsl:call-template>
      <xsl:call-template name="y:ProcessError">
        <xsl:with-param name="FieldName" select="$Field/zj:FieldName"/>
        <xsl:with-param name="Pos" select="1"/>
      </xsl:call-template>
      <input type="hidden" name="{$Field/zj:FieldName}" id="{$Field/zj:FieldName}" value="{$Value}"/>
      <xsl:variable name="CodeTable" select="$zj:Toolkit/*[local-name()=$Field/zj:CodeTable]"/>
      <xsl:variable name="SYhao">'</xsl:variable>
      <table width="100%" cellpadding="0" height="100%" border="0" cellspacing="1">
        <tr>
          <td width="40%">
            <select id="select_{$Field/zj:FieldName}" size="10" style="width:100%" multiple="multiple">
              <xsl:call-template name="y:ProcessAttribute">
                <xsl:with-param name="Field" select="$Field"/>
                <xsl:with-param name="Value" select="$Value"/>
              </xsl:call-template>
              <xsl:for-each select="$CodeTable">
                <xsl:if test="not (contains($Value,concat($SYhao, CODE_VALUE, $SYhao)))">
                  <option value="{CODE_VALUE}">
                    <xsl:value-of select="CODE_NAME"/>
                  </option>
                </xsl:if>
              </xsl:for-each>
            </select>
          </td>
          <TD align="middle" width="20%">
            <TABLE cellSpacing="0" cellPadding="0" width="100%" border="0">
              <TR>
                <TD align="middle" height="20">
                  <A onclick="moveModule('{$Field/zj:FieldName}', false, true)" href="#">添加选定<FONT face="webdings">8</FONT>
                  </A>
                </TD>
              </TR>
              <TR>
                <TD align="middle" height="20">
                  <A onclick="moveModule('{$Field/zj:FieldName}', true, true)" href="#">添加全部<FONT face="webdings">:</FONT>
                  </A>
                </TD>
              </TR>
              <TR>
                <TD align="middle" height="20">
                  <A onclick="moveModule('{$Field/zj:FieldName}', false, false)" href="#">
                    <FONT face="webdings">7</FONT>删除选定</A>
                </TD>
              </TR>
              <TR>
                <TD align="middle" height="20">
                  <A onclick="moveModule('{$Field/zj:FieldName}', true, false)" href="#">
                    <FONT face="webdings">9</FONT>删除全部</A>
                </TD>
              </TR>
              <TR>
                <TD>
                  <BR/>说明：<BR/>按住键盘Shift或Ctrl可多选</TD>
              </TR>
            </TABLE>
          </TD>
          <td width="40%">
            <select id="selected_{$Field/zj:FieldName}" size="10" style="width:100%" multiple="multiple">
              <xsl:call-template name="y:ProcessAttribute">
                <xsl:with-param name="Field" select="$Field"/>
                <xsl:with-param name="Value" select="$Value"/>
              </xsl:call-template>
              <xsl:for-each select="$CodeTable">
                <xsl:if test="contains($Value,concat($SYhao, CODE_VALUE, $SYhao))">
                  <option value="{CODE_VALUE}">
                    <xsl:value-of select="CODE_NAME"/>
                  </option>
                </xsl:if>
              </xsl:for-each>
            </select>
          </td>
        </tr>
      </table>
    </td>
  </xsl:template>
  <xsl:template name="zj:Upload">
    <xsl:param name="Field"/>
    <xsl:param name="Value"/>
    <xsl:param name="Pos"/>
    <xsl:param name="DataRecord"/>
    <xsl:call-template name="zj:Caption">
      <xsl:with-param name="IsEmpty" select="$Field/@IsEmpty = 'true'"/>
      <xsl:with-param name="Title" select="$Field/zj:DisplayName"/>
    </xsl:call-template>
    <td class="td-right">
      <xsl:call-template name="zj:IsTwoColumn">
        <xsl:with-param name="IsTwoColumn" select="$Field/zj:Display/@ThreeColumn"/>
      </xsl:call-template>
      <xsl:call-template name="y:ProcessError">
        <xsl:with-param name="FieldName" select="$Field/zj:FieldName"/>
        <xsl:with-param name="Pos" select="$Pos"/>
      </xsl:call-template>
      <xsl:variable name="ReadOnly" select="$Field/zj:Display/@ReadOnly = 'true'"/>
      <xsl:variable name="TableName" select="ancestor::zj:Table/@TableName"/>
      <xsl:variable name="FieldName" select="$Field/zj:FieldName"/>
      <xsl:variable name="Upload" select="$Field/zj:Upload"/>
      <input type="text" style="width:50%" name="{$FieldName}" id="{$FieldName}" value="{$DataRecord/*[local-name()=$FieldName]}">
        <xsl:if test="$ReadOnly">
          <xsl:attribute name="readonly">readonly</xsl:attribute>
        </xsl:if>
        <xsl:call-template name="y:CopyAttribute">
          <xsl:with-param name="Field" select="$Field"/>
          <xsl:with-param name="Value" select="$Value"/>
          <xsl:with-param name="Pos" select="$Pos"/>
        </xsl:call-template>
        <xsl:attribute name="onkeyup">if (this.value == '') {var row = GetRowIDEx(this);<xsl:value-of select="$TableName"/>.all('<xsl:value-of select="$Upload/@ServerPathField"/>', row).value='';<xsl:value-of select="$TableName"/>.all('<xsl:value-of select="$Upload/@MimeTypeField"/>', row).value='';<xsl:value-of select="$TableName"/>.all('<xsl:value-of select="$Upload/@SizeField"/>', row).value='';}</xsl:attribute>
      </input>
      <input type="hidden" name="{$Upload/@ServerPathField}" id="{$Upload/@ServerPathField}" value="{$DataRecord/*[local-name()=$Upload/@ServerPathField]}"/>
      <input type="hidden" name="{$Upload/@MimeTypeField}" id="{$Upload/@MimeTypeField}" value="{$DataRecord/*[local-name()=$Upload/@MimeTypeField]}"/>
      <input type="hidden" name="{$Upload/@SizeField}" id="{$Upload/@SizeField}" value="{$DataRecord/*[local-name()=$Upload/@SizeField]}"/>
      <input type="hidden" name="{$FieldName}_TYPERULE" id="{$FieldName}_TYPERULE" value="{$Upload/@FileExt}"/>
      <input type="hidden" name="{$FieldName}_MAXSIZE" id="{$FieldName}_MAXSIZE" value="{$Upload/@MaxSize}"/>
      <input name="{$FieldName}_uploadImg" type="button" class="clsButtonFacebt" onclick="OpenUploadPage({$TableName}.all('{$FieldName}_TYPERULE'), {$TableName}.all('{$FieldName}_MAXSIZE'), {$TableName}.all('{$FieldName}'), {$TableName}.all('{$Upload/@ServerPathField}'), {$TableName}.all('{$Upload/@SizeField}'), {$TableName}.all('{$Upload/@MimeTypeField}'), '{$Upload/@OnUploadedEvent}')" value="浏览..."/>
      <xsl:if test="$Upload/@IsView = 'true'">
        <img src="../images/empty.gif" width="1" height="1"/>
        <img src="../images/lookup.gif" alt="预览" style="border=0;cursor:hand" align="middle" width="18" height="17" name="{$Field/zj:FieldName}_viewImg" onmouseover="ViewUpload({$TableName}.all('{$Upload/@ServerPathField}').value)"/>
      </xsl:if>
      <xsl:call-template name="y:ProcessHint">
        <xsl:with-param name="Field" select="$Field"/>
      </xsl:call-template>
    </td>
  </xsl:template>
</xsl:stylesheet>
